package com.gexiao.core.type.filter;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * 自定义TypeFilter {@link org.springframework.core.type.filter.TypeFilter}
 */
public class MyTypeFilter implements TypeFilter {
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        // 当前注解的元数据
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        // 当前类的元数据
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        // 当前类的资源信息
        Resource resource = metadataReader.getResource();
        String className = classMetadata.getClassName();
        if (className.toLowerCase().contains("er")) {
            System.out.println("className = " + className);
            return true;
        }
        return false;
    }
}
